const wx = require('./common');
// 获取用户列表
async function test(data) {
	let access_token = await wx.getToken()
	let Url =
		`https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=${access_token}&next_openid`
	let listRes = await uniCloud.httpclient.request(Url, {
		method: 'POST',
		data: JSON.stringify(data),
		dataType: 'json'
	})
	if(listRes.status===200){
		return {
			data: listRes.data,
			status: 200
		}
	}else {
		return {
			msg: '服务器出错',
			data: false,
			status: 400
		}
	}
}

// 添加自定义菜单
async function del(data) {
	// 获取参数
	let access_token = await wx.getToken()
	let Url =
		`https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=${access_token}`
	let result = await uniCloud.httpclient.request(Url, {
		method: 'POST',
		data:JSON.stringify(data),
		dataType: 'json'
	})
	// 添加到后台服务器
	return result
}

// 添加自定义菜单
async function add(data) {
	// 获取参数
	let access_token = await wx.getToken()
	let Url =
		`https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=${access_token}`
	let result = await uniCloud.httpclient.request(Url, {
		method: 'POST',
		data:JSON.stringify(data),
		dataType: 'json'
	})
	// 添加到后台服务器
	return result
}


module.exports = {
	add,
	test,
	del
}
